<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #main {
            width: 400px;
            height: 400px;
            border: 1px;
        }

        button {
            width: 300px;
            height: 150px;
            font-size: 24px;
        }
    </style>
</head>

<body>
    <script src=""></script>
    <div id="main" style="width: 600px;height:400px;"></div>
    <button onclick="f()">返回首页</button>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.5.1/dist/echarts.min.js"></script>
    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var aaa = echarts.init(document.getElementById('main'));

        // 指定图表的配置项和数据
        function fa() {
            var xhr = new XMLHttpRequest()
            xhr.open('get', 'https://liu.zzgoodqc.cn/goodsx/goodslist')
            xhr.send()
            xhr.responseType = 'json'
            xhr.onload = () => {
                // console.log(xhr.response.data);
                var a = []
                var b = []
                xhr.response.data.forEach(item => {
                    // console.log(item.goods_name);
                    a.push(item.goods_name)
                    b.push(item.sold)
                })
                // console.log(a);
                option = {

                    xAxis: {
                        type: 'category',
                        data: a
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            data: b,
                            type: 'bar'
                        }
                    ]
                };

                // 使用刚指定的配置项和数据显示图表。
                aaa.setOption(option);

            }
            xhr.onerror = (m) => {
                console.log(m);
            }
        } fa()

        function f(){
            location.assign("../首页/首页.html")
        }
    </script>
</body>

</html>